<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>全名红包记录</title>
    <script src="../commonCss.js"></script>
    <script src="../commonJs.js"></script>
    <link rel="stylesheet" href="../../css/common.css">
</head>

<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <div class="ctc_title">红包记录</div>
    <div class="down_line"></div>
</section>

<!-- Main content -->
<section class="content" >
    <div class="row">
        <div class="col-xs-12">
            <div class="box-header">
                <form class="form-inline">
                    <div class="form-group">
                        <label>查询：</label>
                        <select id="type" class="form-control" style="text-align: center;font-size: 12px ;width:110px;">
                            <option value="0">全民红包</option>
                            <option value="1">大转盘红包</option>
                        </select>&nbsp;&nbsp;
                        <input style="width: 220px;" class="form-control" type="text" id="searchKey"  placeholder="输入用户账号/手机号/红包名搜索"/>
                    </div>
                    <div class="form-group">
                        <button type="button"  onclick="getData()"  class="btn btn-block btn-primary">搜索</button>
                    </div>
                    <div class="form-group" style="margin-left: 2%">
                        <button type="button"  onclick="restRedPag()"  class="btn btn-block btn-primary">重置红包位置</button>
                    </div>
                    <div class="form-group" style="margin-left: 1%">
                        <button type="button"  onclick="addRedPagMoney()"  class="btn btn-block btn-primary">红包池充值</button>
                    </div>

                    <div class="form-group" style="float: right">
                        <font color="#006400" size="5px">总次数：</font><span style="color: red;font-size: 25px;" id="totalCount"></span>&nbsp;&nbsp;&nbsp;
                        <font color="#006400" size="5px">总金额：</font><span style="color: red;font-size: 25px;" id="totalMoney"></span>
                    </div>
                </form>
            </div>

            <div class="box-body" style="height:100%;">
                <table id="dataList" class="table table-bordered table-hover" >
                    <thead>
                    <tr>
                        <th>用户账号</th>
                        <th>用户昵称</th>
                        <th>用户手机</th>
                        <th>红包金额(元)</th>
                        <th>抽奖时间</th>
                    </tr>
                    </thead>
                    <tbody >
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>

<!-- 【红包池充值】弹出窗内容 -->
<div class="modal" id="resetPanel" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <input type="hidden" id="changeId">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" align="center">向红包池充值</h4>
            </div>
            <div class="modal-body">
                <div id="account_div" class="form-group">
                    <label class="col-md-2 control-label" >充值金额:</label>
                    <div class="col-md-10">
                        <input class="form-control" type="number" name="addMoney" id="addMoney">
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="text-align: center;">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>&nbsp;&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-primary"  onclick="confirmRest();">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- page script -->
<script>
    $(document).ready(function() {
        //加载数据
        getData();

    });

    // 加载数据
    function getData(){
        getToalData();
        var table = $('#dataList').DataTable({
            "destroy": true,   //可以重新初始化，用于搜索
            "lengthChange": false,
            "ordering": false,   //排序
            "info": true,		   //
            "autoWidth": false,   //宽度自动
            "paging": true,      //分页
            "searching": false,  //全局搜索关闭
            "processing": true,  //开启显示‘正在加载.../processing’
            "serverSide":true,    //true代表后台处理分页，false代表前台处理分页
            "ajax" :  {
                url:"/dataStatist/getRedPagDetailList",
                type:"POST",
                data:{
                    type : $("#type").val(),
                    key : $("#searchKey").val()
                },
                dataSrc: function (myJson) {
                    return myJson.data.data;
                }
            },
            //参数显示
            "columns": [
                {"data": "account", 'sClass': "text-center",'width': '10%'},
                {"data": "username", 'sClass': "text-center",'width': '8%'},
                {"data": "mobile", 'sClass': "text-center",'width': '10%'},
                {"data": "money", 'sClass': "text-center",'width': '5%'},
                {"data": "createTime", 'sClass': "text-center",'width': '10%',
                    "render":function( data, type, full, meta) {
                        return toDate(data).format('yyyy-MM-dd HH:mm:ss');
                    }
                }
            ],

            //是否开启主题
            "bJQueryUI": true,
            "oLanguage": {    // 语言设置
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "检索:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            }
        });
    }

    function  getToalData(){
        $.ajax({
            type:"POST",
            url:"/dataStatist/getRedPagDetailTotal",
            async : true,//默认就是true
            dataType:"json",
            data:{
                type : $("#type").val(),
                key : $("#searchKey").val()
            },
            success:function(result){
                $("#totalCount").html(result.data.count);
                $("#totalMoney").html(result.data.totalMoney.toFixed(2));
            },
            failure:function(result) {
                alert('网络错误！');
            },
        });
    }

    //重置红包分布
    function restRedPag() {
        if(confirm("确定要重置红包分布吗？")) {
            $.ajax({
                type: "POST",
                url: "/sysconfig/newRedPageSeat",
                async: true,//默认就是true
                success: function (result) {
                    layer.msg(result.message);
                },
                failure: function (result) {
                    layer.msg('网络错误！');
                },
            });
        }
    }
    //奖池充值弹框
    function addRedPagMoney() {
        $("#addMoney").val("");
        $("#resetPanel").modal("show");//弹窗打开
    }

    function confirmRest() {
		let addMoney = $("#addMoney").val();
        if(addMoney == ""){
            layer.msg("充值金额不能为空！");
            return;
        }
        let reg = /^([1-9]\d{0,8}|0)(\.\d{1,2})?$/;
        if (!reg.test(addMoney)) {
            layer.msg("充值金额填写不正确！(注：最小0.01元，最大9999999.99元)");
            return ;
        }
        $.ajax({
            type:"POST",
            url:"/sysconfig/setRedPageMoney",
            async : true,//默认就是true
            data:{
                uid : 0,
                totalMoney : $("#addMoney").val()
            },
            success:function(result){
                $("#resetPanel").modal("hide");
                layer.msg(result.message);
            },
            failure:function(result) {
                layer.msg('网络错误！');
            },
        });
    }
</script>
</body>
</html>
